package cn.hl.sfzy.controller;


import cn.hl.sfzy.entity.Publicity;
import cn.hl.sfzy.service.PublicityService;
import cn.hl.sfzy.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PublicityController
 * @Description TOOO
 * @Author Lilysi
 * @Date 2024//10//24//16:10
 * @Version 1.0
 */
@RestController
@RequestMapping("/Publicity")
@CrossOrigin
public class PublicityController {
    @Autowired
    private PublicityService publicityService;
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        int i = publicityService.delete(id);
        return Result.success("删除成功");
    }
    @PostMapping
    public Result insert(@RequestBody Publicity publicity) {
        int i = publicityService.insert(publicity);
        return Result.success(publicity);
    }
    @PutMapping
    public Result update(@RequestBody Publicity publicity) {
        int i = publicityService.update(publicity);
        return Result.success(publicity);
    }
    @GetMapping("/pageSelect")
    public Result pageSelect(@RequestParam(required = false,defaultValue = "1") int pageNum, @RequestParam(required = false,defaultValue = "5") int pageSize, Publicity publicity) {
        PageInfo<Publicity> byPage = publicityService.findByPage(pageNum, pageSize, publicity);
        return Result.success(byPage);
    }
}
